<template>
  <div class="login-page">
    <el-form class="el-form">
      <div class="form-label">
        <h1>请登录</h1>
      </div>

      <el-form-item label="账号">
        <el-input v-model="user.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="user.password"></el-input>
      </el-form-item>
      <el-form-item style="display: flex;">
        <el-button type="primary" style="width: 100%" @click="submitHandler">登录</el-button>
      </el-form-item>
      <div class="login-addition">
        <el-button link >忘记密码</el-button>
        <el-button @click="toRegister">注册</el-button>
      </div>
    </el-form>
  </div>

</template>

<script>
import { ref } from 'vue'
import { userLogin } from '@/api/user'
import router from '@/router'

export default {
  name: 'UserLogin',
  setup () {
    return {
      user: ref({
        username: '',
        password: ''
      })
    }
  },
  methods: {
    submitHandler () {
      this.$store.dispatch('login', this.user)
      // userLogin(this.user).then((val) => {
      //   console.log(val)
      //   router.back()
      // })
    },
    toRegister () {
      router.push('/register')
    }
  }
}
</script>

<style scoped>
.login-page{
  width: 600px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 600px;
  background-color: #e3eeef;
}
.form-label{
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 30px 30px;
  padding-top: 0;
}
.login-addition{
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-between;
}
.el-form{
  width: 300px;
}
</style>
